﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace lcmyjobs.DAL
{
	/// <summary>
	/// 数据访问类:enterprise_releasejob
	/// </summary>
	public partial class enterprise_releasejob
	{
		public enterprise_releasejob()
		{}
        /// <summary>
        /// 使浏览次数+1
        /// </summary>
        /// <param name="enterprise_bid"></param>
        /// <returns></returns>
        public bool UpdateBcount(int enterprise_rid)
        {
            int rowsAffected = 0;
            SqlParameter[] para = 
            {
                new SqlParameter("@enterprise_rid",SqlDbType.Int)
            };

            para[0].Value = enterprise_rid;

            DbHelperSQL.RunProcedure("P_Update_enterprise_releasejob_bcount", para, out rowsAffected);

            if (rowsAffected > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        public DataSet GetJobsInfo(bool isfrirt,bool reward,bool hunter,bool vip,bool newjob,bool workerclass,
                                    int atid,int currentPageIndex, int pageSize,
                                    out int c_isfrist,out int c_reward,out int c_hunter,out int c_vip,out int c_newjob,out int c_workerclass)
        {
            DataSet ds = null;

            c_isfrist = 0;
            c_reward = 0;
            c_newjob = 0;
            c_hunter = 0;
            c_vip = 0;
            c_workerclass = 0;

            SqlParameter[] para = 
            {
                new SqlParameter("@isfrist",SqlDbType.Bit),
                new SqlParameter("@newjob",SqlDbType.Bit),
                new SqlParameter("@hunter",SqlDbType.Bit),
                new SqlParameter("@reward",SqlDbType.Bit),
                new SqlParameter("@vip",SqlDbType.Bit),
                new SqlParameter("@workerclass",SqlDbType.Bit),
                new SqlParameter("@currentPageIndex",SqlDbType.Int),
                new SqlParameter("@pageSize",SqlDbType.Int),
                new SqlParameter("@atid",SqlDbType.Int),
                new SqlParameter("@count_isfrist",SqlDbType.Int),
                new SqlParameter("@count_newjob",SqlDbType.Int),
                new SqlParameter("@count_hunter",SqlDbType.Int),
                new SqlParameter("@count_reward",SqlDbType.Int),
                new SqlParameter("@count_vip",SqlDbType.Int),
                new SqlParameter("@count_workerclass",SqlDbType.Int)

            };


            para[0].Value = isfrirt;
            para[1].Value = newjob;
            para[2].Value = hunter;
            para[3].Value = reward;
            para[4].Value = vip;
            para[5].Value = workerclass;
            para[6].Value = currentPageIndex;
            para[7].Value = pageSize;
            para[8].Value = atid;
            para[9].Direction = ParameterDirection.Output;
            para[10].Direction = ParameterDirection.Output;
            para[11].Direction = ParameterDirection.Output;
            para[12].Direction = ParameterDirection.Output;
            para[13].Direction = ParameterDirection.Output;
            para[14].Direction = ParameterDirection.Output;



            ds = DbHelperSQL.RunProcedure("P_Get_JobsInfo", para, "ds");

            if (!Convert.IsDBNull(para[9].Value))
            {
                c_isfrist = Convert.ToInt32(para[9].Value);
            }
            if (!Convert.IsDBNull(para[10].Value))
            {
                c_newjob = Convert.ToInt32(para[10].Value);
            }
            if (!Convert.IsDBNull(para[11].Value))
            {
                c_hunter = Convert.ToInt32(para[11].Value);
            }
            if (!Convert.IsDBNull(para[12].Value))
            {
                c_reward = Convert.ToInt32(para[12].Value);
            }
            if (!Convert.IsDBNull(para[13].Value))
            {
                c_vip = Convert.ToInt32(para[13].Value);
            }
            if (!Convert.IsDBNull(para[14].Value))
            {
                c_workerclass = Convert.ToInt32(para[14].Value);
            }
         
            return ds;
        }
        /// <summary>
        /// 根据职位ID获取发布此职位的单位信息及职位信息
        /// </summary>
        /// <param name="enterprise_rid"></param>
        /// <returns></returns>
        public DataSet GetBasicAndJobsInfoByRid(int enterprise_rid)
        {
            SqlParameter[] para = 
            {
                new SqlParameter("@enterprise_rid",SqlDbType.Int)
              
            };

            para[0].Value = enterprise_rid;


            return DbHelperSQL.RunProcedure("P_Get_releasJobAndBasicInfoByRid", para, "ds");
        }
        /// <summary>
        /// 根据条件获取相应信息列表（hunter、reward、vip、newjobs）
        /// </summary>
        /// <param name="condition">（hunter猎头职位、reward悬赏职位、vip、newjobs最新职位）</param>
        /// <param name="atid"></param>
        /// <param name="currentPageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public DataSet GetJobsInfoByCondition(string condition, int atid, int currentPageIndex, int pageSize, out int count)
        {
            SqlParameter[] para = 
            {
                new SqlParameter("@currentPageIndex",SqlDbType.Int),
                new SqlParameter("@pageSize",SqlDbType.Int),
                new SqlParameter("@count",SqlDbType.Int),
                new SqlParameter("@atid",SqlDbType.Int),
                new SqlParameter("@condition",SqlDbType.VarChar,10)
            };

            para[0].Value = currentPageIndex;
            para[1].Value = pageSize;
            para[2].Direction = ParameterDirection.Output;
            para[3].Value = atid;
            para[4].Value = condition;


            DataSet ds = DbHelperSQL.RunProcedure("P_Get_jobsInfoByCondition", para, "ds");

            if (!Convert.IsDBNull(para[2].Value))
            {
                count = Convert.ToInt32(para[2].Value);
            }
            else
            {
                count = 0;
            }

            return ds;
        }

        /// <summary>
        /// 根据网站获取首页信息
        /// </summary>
        /// <param name="countH">猎头职位数量</param>
        /// <param name="countR">悬赏职位数量</param>
        /// <param name="countVIP">vip职位数</param>
        /// <param name="countNEW">最新招聘职位数</param>
        /// <param name="atid">网站</param>
        /// <returns></returns>
        public DataSet GetIndexInfo(int countH,int countR,int countVIP,int countNEW,int atid)
        {
            SqlParameter[] para = 
            {
                new SqlParameter("@counthunter",SqlDbType.Int),
                new SqlParameter("@countreward",SqlDbType.Int),
                new SqlParameter("@countvip",SqlDbType.Int),
                new SqlParameter("@countnew",SqlDbType.Int),
                new SqlParameter("@atid",SqlDbType.Int)
            };

            para[0].Value = countH;
            para[1].Value = countR;
            para[2].Value = countVIP;
            para[3].Value = countNEW;
            para[4].Value = atid;

            return DbHelperSQL.RunProcedure("P_Get_IndexInfo", para, "ds");

        }
        /// <summary>
        /// 获取首页猎头职位
        /// </summary>
        /// <param name="countH"></param>
        /// <param name="atid"></param>
        /// <returns></returns>
        public DataSet GetIndexInfoHunter(int countH, int atid)
        {
            SqlParameter[] para = 
            {
                new SqlParameter("@counthunter",SqlDbType.Int),              
                new SqlParameter("@atid",SqlDbType.Int)
            };

            para[0].Value = countH;
            para[1].Value = atid;

            return DbHelperSQL.RunProcedure("P_Get_IndexInfo_Hunter", para, "ds");

        }
        /// <summary>
        /// 获取首页悬赏职位
        /// </summary>
        /// <param name="countR"></param>
        /// <param name="atid"></param>
        /// <returns></returns>
        public DataSet GetIndexInfoReward(int countR, int atid)
        {
            SqlParameter[] para = 
            {
                new SqlParameter("@countreward",SqlDbType.Int),           
                new SqlParameter("@atid",SqlDbType.Int)
            };

            para[0].Value = countR;
            para[1].Value = atid;

            return DbHelperSQL.RunProcedure("P_Get_IndexInfo_Reward", para, "ds");

        }
        /// <summary>
        /// 获取首页VIP职位
        /// </summary>
        /// <param name="countVip"></param>
        /// <param name="atid"></param>
        /// <returns></returns>
        public DataSet GetIndexInfoVip(int countVip, int atid)
        {
            SqlParameter[] para = 
            {
                new SqlParameter("@countvip",SqlDbType.Int),        
                new SqlParameter("@atid",SqlDbType.Int)
            };

            para[0].Value = countVip;
            para[1].Value = atid;

            return DbHelperSQL.RunProcedure("P_Get_IndexInfo_Vip", para, "ds");

        }
        /// <summary>
        /// 获取首页最新职位
        /// </summary>
        /// <param name="countNew"></param>
        /// <param name="atid"></param>
        /// <returns></returns>
        public DataSet GetIndexInfoNew(int countNew, int atid)
        {
            SqlParameter[] para = 
            {
                new SqlParameter("@countnew",SqlDbType.Int),        
                new SqlParameter("@atid",SqlDbType.Int)
            };

            para[0].Value = countNew;
            para[1].Value = atid;

            return DbHelperSQL.RunProcedure("P_Get_IndexInfo_New", para, "ds");

        }


        /// <summary>
        /// 根据网站获取全部揭榜职位信息
        /// </summary>
        /// <param name="atid"></param>
        /// <param name="currentPageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public DataSet GetAllOfferJobdByAtid(int atid, int currentPageIndex, int pageSize, out int count)
        {
            SqlParameter[] para = 
            {
                new SqlParameter("@currentPageIndex",SqlDbType.Int),
                new SqlParameter("@pageSize",SqlDbType.Int),
                new SqlParameter("@count",SqlDbType.Int),
                new SqlParameter("@atid",SqlDbType.Int)
            };

            para[0].Value = currentPageIndex;
            para[1].Value = pageSize;
            para[2].Direction = ParameterDirection.Output;
            para[3].Value = atid;


            DataSet ds = DbHelperSQL.RunProcedure("P_Get_AllEnterpriseOffer", para, "ds");

            if (!Convert.IsDBNull(para[2].Value))
            {
                count = Convert.ToInt32(para[2].Value);
            }
            else
            {
                count = 0;
            }

            return ds;
        }
        /// <summary>
        /// 根据网站获取全部悬赏职位
        /// </summary>
        /// <param name="atid"></param>
        /// <param name="currentPageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public DataSet GetAllRewardJobdByAtid(int atid, int currentPageIndex, int pageSize, out int count)
        {
            SqlParameter[] para = 
            {
                new SqlParameter("@currentPageIndex",SqlDbType.Int),
                new SqlParameter("@pageSize",SqlDbType.Int),
                new SqlParameter("@count",SqlDbType.Int),
                new SqlParameter("@atid",SqlDbType.Int)
            };

            para[0].Value = currentPageIndex;
            para[1].Value = pageSize;
            para[2].Direction = ParameterDirection.Output;
            para[3].Value = atid;


            DataSet ds = DbHelperSQL.RunProcedure("P_Get_AllRewardJobsByAtid", para, "ds");

            if (!Convert.IsDBNull(para[2].Value))
            {
                count = Convert.ToInt32(para[2].Value);
            }
            else
            {
                count = 0;
            }

            return ds;
        }
        /// <summary>
        /// 根据网站获取全部猎头职位
        /// </summary>
        /// <param name="atid"></param>
        /// <param name="currentPageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public DataSet GetAllHuntertJobdByAtid(int atid, int currentPageIndex, int pageSize, out int count)
        {
            SqlParameter[] para = 
            {
                new SqlParameter("@currentPageIndex",SqlDbType.Int),
                new SqlParameter("@pageSize",SqlDbType.Int),
                new SqlParameter("@count",SqlDbType.Int),
                new SqlParameter("@atid",SqlDbType.Int)
            };

            para[0].Value = currentPageIndex;
            para[1].Value = pageSize;
            para[2].Direction = ParameterDirection.Output;
            para[3].Value = atid;


            DataSet ds = DbHelperSQL.RunProcedure("P_Get_Allenterprise_askhunterByAtid", para, "ds");

            if (!Convert.IsDBNull(para[2].Value))
            {
                count = Convert.ToInt32(para[2].Value);
            }
            else
            {
                count = 0;
            }

            return ds;
        }
        /// <summary>
        /// 根据网站获取所有急聘职位信息
        /// </summary>
        /// <param name="atid"></param>
        /// <param name="currentPageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public DataSet GetAllIsFristRelesJobByAtid(int atid, int currentPageIndex, int pageSize, out int count)
        {
            SqlParameter[] para = 
            {
                new SqlParameter("@currentPageIndex",SqlDbType.Int),
                new SqlParameter("@pageSize",SqlDbType.Int),
                new SqlParameter("@count",SqlDbType.Int),
                new SqlParameter("@atid",SqlDbType.Int)
            };

            para[0].Value = currentPageIndex;
            para[1].Value = pageSize;
            para[2].Direction = ParameterDirection.Output;
            para[3].Value = atid;


            DataSet ds = DbHelperSQL.RunProcedure("P_Get_AllIsFristReleasejobsByAtid", para, "ds");

            if (!Convert.IsDBNull(para[2].Value))
            {
                count = Convert.ToInt32(para[2].Value);
            }
            else
            {
                count = 0;
            }

            return ds;
        }
        /// <summary>
        /// 根据审核状态获取职位信息
        /// </summary>
        /// <param name="status"></param>
        /// <param name="currentPageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public DataSet GetRelesJobByStatus(int atid,int status, int currentPageIndex, int pageSize, out int count)
        {
            SqlParameter[] para = 
            {
                new SqlParameter("@currentPageIndex",SqlDbType.Int),
                new SqlParameter("@pageSize",SqlDbType.Int),
                new SqlParameter("@count",SqlDbType.Int),
                new SqlParameter("@status",SqlDbType.Int),
                new SqlParameter("@atid",SqlDbType.Int)
            };

            para[0].Value = currentPageIndex;
            para[1].Value = pageSize;
            para[2].Direction = ParameterDirection.Output;
            para[3].Value = status;
            para[4].Value = atid;


            DataSet ds = DbHelperSQL.RunProcedure("P_Get_AllreleasejobByStatus", para, "ds");

            if (!Convert.IsDBNull(para[2].Value))
            {
                count = Convert.ToInt32(para[2].Value);
            }
            else
            {
                count = 0;
            }

            return ds;
        }
        /// <summary>
        /// 获取VIP职位信息
        /// </summary>
        /// <param name="currentPageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public DataSet GetVipJobsInfo(int currentPageIndex, int pageSize, out int count)
        {
            SqlParameter[] para = 
            {
                new SqlParameter("@currentPageIndex",SqlDbType.Int),
                new SqlParameter("@pageSize",SqlDbType.Int),
                new SqlParameter("@count",SqlDbType.Int)
            };

            para[0].Value = currentPageIndex;
            para[1].Value = pageSize;
            para[2].Direction = ParameterDirection.Output;

            DataSet ds = DbHelperSQL.RunProcedure("P_Get_vipJobsInfo", para, "ds");

            if (!Convert.IsDBNull(para[2].Value))
            {
                count = Convert.ToInt32(para[2].Value);
            }
            else
            {
                count = 0;
            }
            
            return ds;
        }
        /// <summary>
        /// 根据条件获取所有职位信息
        /// </summary>
        /// <param name="condition">“isFrist”急聘职位，“isReward”悬赏职位</param>
        /// <param name="currentPageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public DataSet GetReleaseJobsByCondition(string condition,int atid, string value,int currentPageIndex, int pageSize, out int count)
        {
            DataSet ds = null;

            SqlParameter[] para = 
            {
                new SqlParameter("@condition",SqlDbType.VarChar,20),
                new SqlParameter("@currentPageIndex",SqlDbType.Int),
                new SqlParameter("@pageSize",SqlDbType.Int),
                new SqlParameter("@count",SqlDbType.Int),
                new SqlParameter("@value",SqlDbType.VarChar,20),
                new SqlParameter("@atid",SqlDbType.Int)

            };

            para[0].Value = condition;
            para[1].Value = currentPageIndex;
            para[2].Value = pageSize;
            para[3].Direction = ParameterDirection.Output;
            para[4].Value = value;
            para[5].Value = atid;

            ds = DbHelperSQL.RunProcedure("P_Get_allReleasejobsByCondition",para,"ds");

            if (!Convert.IsDBNull(para[3].Value))
            {
                count = Convert.ToInt32(para[3].Value);
            }
            else
            {
                count = 0;
            }

            return ds;
        }
        /// <summary>
        /// 获取急聘职位
        /// </summary>
        /// <returns></returns>
        public DataSet GetIsFristJobs()
        {
            string str = "  SELECT  [name],[job_name],[enterprise_rid] FROM View_enterprise_search WHERE isFrist=1 ";

            return DbHelperSQL.Query(str);
        }

        /// <summary>
        /// 职位搜索
        /// </summary>
        /// <param name="sj">搜索条件实体</param>
        /// <param name="count">返回行数</param>
        /// <returns></returns>
        public DataSet GetSearch(lcmyjobs.Model.searchjobs sj,int atid, int currentPageIndex, int pageSize, out int count)
        {
            SqlParameter[] para = 
            {
                new SqlParameter("@workerclass",SqlDbType.Int),             // 0
                new SqlParameter("@releasetime",SqlDbType.Int),             // 1
                new SqlParameter("@languages_level",SqlDbType.Int),         // 2
                new SqlParameter("@languages_id",SqlDbType.Int),            // 3
                new SqlParameter("@workexp_id",SqlDbType.Int),              // 4
                new SqlParameter("@edus_id",SqlDbType.Int),                 // 5
                new SqlParameter("@salarym",SqlDbType.Int),                 // 6
                new SqlParameter("@area_name1",SqlDbType.NVarChar,20),      // 7
                new SqlParameter("@area_name2",SqlDbType.NVarChar,20),      // 8
                new SqlParameter("@area_name3",SqlDbType.NVarChar,20),      // 9
                new SqlParameter("@major_name1",SqlDbType.NVarChar,20),     // 10
                new SqlParameter("@major_name2",SqlDbType.NVarChar,20),     // 11
                new SqlParameter("@major_name3",SqlDbType.NVarChar,20),     // 12
                new SqlParameter("@tradename1",SqlDbType.NVarChar,20),      // 13
                new SqlParameter("@tradename2",SqlDbType.NVarChar,20),      // 14
                new SqlParameter("@tradename3",SqlDbType.NVarChar,20),      // 15
                new SqlParameter("@job_name1",SqlDbType.NVarChar,20),       // 16
                new SqlParameter("@job_name2",SqlDbType.NVarChar,20),       // 17
                new SqlParameter("@job_name3",SqlDbType.NVarChar,20),       // 18
                new SqlParameter("@currentPageIndex",SqlDbType.Int),        // 19
                new SqlParameter("@pageSize",SqlDbType.Int),                // 20
                new SqlParameter("@count",SqlDbType.Int),                   // 21
                new SqlParameter("@atid",SqlDbType.Int),                    // 22
                new SqlParameter("@area_name4",SqlDbType.NVarChar,20),      // 23
                new SqlParameter("@area_name5",SqlDbType.NVarChar,20),      // 24
                new SqlParameter("@area_name6",SqlDbType.NVarChar,20),      // 25
                new SqlParameter("@keywords",SqlDbType.NVarChar,20)         // 26

            };

            para[0].Value = sj.workerclass;
            para[1].Value = sj.releasetime;
            para[2].Value = sj.languages_level;
            para[3].Value = sj.languages_id;
            para[4].Value = sj.workexp_id;
            para[5].Value = sj.edus_id;
            para[6].Value = sj.salarym;
            para[7].Value = sj.area_name1;
            para[8].Value = sj.area_name2;
            para[9].Value = sj.area_name3;
            para[10].Value = sj.major_name1;
            para[11].Value = sj.major_name2;
            para[12].Value = sj.major_name3;
            para[13].Value = sj.tradename1;
            para[14].Value = sj.tradename2;
            para[15].Value = sj.tradename3;
            para[16].Value = sj.job_name1;
            para[17].Value = sj.job_name2;
            para[18].Value = sj.job_name3;
            para[19].Value = currentPageIndex;
            para[20].Value = pageSize;
            para[21].Direction = ParameterDirection.Output;
            para[22].Value = atid;
            para[23].Value = sj.area_name4;
            para[24].Value = sj.area_name5;
            para[25].Value = sj.area_name6;
            para[26].Value = sj.key_words;


            DataSet ds = DbHelperSQL.RunProcedure("P_Get_enterprise_jobsSearch", para, "ds");

            count = Convert.ToInt32(para[21].Value);

            return ds;
            
        }
        /// <summary>
        ///  获取职位统计信息（包含应聘此职位的人数）
        /// </summary>
        /// <param name="enterprise_bid">企业ID</param>
        /// <param name="currentPageIndex">当前页</param>
        /// <param name="pageSize">每页显示条目数</param>
        /// <param name="count">总条目数</param>
        /// <returns>返回的DataSet第2个表是企业名称</returns>
        public DataSet Get_enterprise_releasejobtotal(int enterprise_bid,int currentPageIndex,int pageSize,int type,out int count)
        {
            SqlParameter[] para = 
            {
                new SqlParameter("@enterprise_bid",SqlDbType.Int),
                new SqlParameter("@currentPageIndex",SqlDbType.Int),
                new SqlParameter("@pageSize",SqlDbType.Int),
                new SqlParameter("@type",SqlDbType.Int),
                new SqlParameter("@count",SqlDbType.Int)
            };

            para[0].Value = enterprise_bid;
            para[1].Value = currentPageIndex;
            para[2].Value = pageSize;
            para[3].Value = type;
            para[4].Direction = ParameterDirection.Output;

            DataSet ds = DbHelperSQL.RunProcedure("P_Get_enterprise_releasejobtotal", para, "ds");

            count = Convert.ToInt32(para[4].Value);


            return ds;
        }
        /// <summary>
        /// 批量个更改
        /// </summary>
        /// <param name="keywords">关键字</param>
        /// <param name="value">更改值</param>
        /// <param name="where">更改条件enterprise_rid</param>
        /// <returns></returns>
        public bool UpdateWhere(string keywords,string value,string where)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update enterprise_releasejob set " + keywords + " = '" + value + "' ");

            if (!string.IsNullOrEmpty(where))
            {
                strSql.Append(" where enterprise_rid in (" + where + ")  ");
            }

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 得到发布职位信息（返回的dataset中表一发布职位基本信息，表二发布职位的地区，表三发布职位的专业）
        /// </summary>
        /// <param name="enterprise_rid"></param>
        /// <returns></returns>
        public DataSet GetReleaseJob(int enterprise_rid)
        {
            SqlParameter[] para = { new SqlParameter("@enterprise_rid",SqlDbType.Int)};

            para[0].Value = enterprise_rid;

            return DbHelperSQL.RunProcedure("P_Get_enterprise_releasejob", para, "ds");
        }

        /// <summary>
        /// 得到发布职位信息（包括发布此职位的单位所发布的所有职位信息）
        /// </summary>
        /// <param name="enterprise_rid"></param>
        /// <returns>（返回的dataset中表一发布职位基本信息，表二发布职位的地区，表三发布职位的专业，表四 此单位所发布的所有职位信息，职位名和职位主键）</returns>
        public DataSet GetAllReleaseJob(int enterprise_rid,int atid)
        {
            SqlParameter[] para = { new SqlParameter("@enterprise_rid", SqlDbType.Int),
                                    new SqlParameter("@atid",SqlDbType.Int)};

            para[0].Value = enterprise_rid;
            para[1].Value = atid;

            return DbHelperSQL.RunProcedure("P_Get_enterprise_allreleaseJob", para, "ds");
        }

        public bool isjob(int rid, string key, string val )
        {
            int cnt=0;
            bool result = false;
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(*) from enterprise_releasejob where enterprise_rid = '" +rid.ToString() +"' and "  + key + " = '" + val + "' ");
            DataSet ds = DbHelperSQL.Query(strSql.ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                cnt = Convert.ToInt32( ds.Tables[0].Rows[0][0].ToString() );
            }

            if (cnt > 0)
            {
                result = true;
            }
            return result;

        }
        
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("enterprise_rid", "enterprise_releasejob"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int enterprise_rid)
		{
			int rowsAffected;
			SqlParameter[] parameters = {
					new SqlParameter("@enterprise_rid", SqlDbType.Int,4)
};
			parameters[0].Value = enterprise_rid;

			int result= DbHelperSQL.RunProcedure("enterprise_releasejob_Exists",parameters,out rowsAffected);
			if(result==1)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		///  增加一条数据
		/// </summary>
		public int Add(lcmyjobs.Model.enterprise_releasejob model)
		{
			int rowsAffected;
			SqlParameter[] parameters = {
					new SqlParameter("@enterprise_rid", SqlDbType.Int,4),
					new SqlParameter("@enterprise_bid", SqlDbType.Int,4),
					new SqlParameter("@enterprise_bh", SqlDbType.Char,5),
					new SqlParameter("@jobs_name", SqlDbType.NVarChar,50),
					new SqlParameter("@jobclass", SqlDbType.NVarChar,20),
					new SqlParameter("@workercount", SqlDbType.SmallInt,2),
					new SqlParameter("@jobdep", SqlDbType.NVarChar,20),
					new SqlParameter("@salarym", SqlDbType.VarChar,30),
					new SqlParameter("@salaryy", SqlDbType.VarChar,30),
					new SqlParameter("@validity", SqlDbType.Int,4),
					new SqlParameter("@workerclass", SqlDbType.TinyInt,1),
					new SqlParameter("@edus_id", SqlDbType.Int,4),
					new SqlParameter("@workexp_id", SqlDbType.Int,4),
					new SqlParameter("@jobduty", SqlDbType.NVarChar,1000),
					new SqlParameter("@jobrequirement", SqlDbType.NVarChar,1000),
					new SqlParameter("@releasetime", SqlDbType.DateTime),
					new SqlParameter("@isuse", SqlDbType.Bit,1),
					new SqlParameter("@languages_id", SqlDbType.Int,4),
					new SqlParameter("@bcount", SqlDbType.Int,4),
					new SqlParameter("@isfrist", SqlDbType.Bit,1),
					new SqlParameter("@status", SqlDbType.TinyInt,1),
                    new SqlParameter("@area_name1", SqlDbType.NVarChar,20),   
                    new SqlParameter("@area_name2", SqlDbType.NVarChar,20),
                    new SqlParameter("@area_name3", SqlDbType.NVarChar,20),
                    new SqlParameter("@marjor_name1", SqlDbType.NVarChar,20),
                    new SqlParameter("@marjor_name2", SqlDbType.NVarChar,20),
                    new SqlParameter("@marjor_name3", SqlDbType.NVarChar,20),
                    new SqlParameter("@languages_level",SqlDbType.NVarChar,2),
                    new SqlParameter("@rewardmoney",SqlDbType.Float),
                    new SqlParameter("@job_child_class",SqlDbType.NVarChar,20)};
			parameters[0].Direction = ParameterDirection.Output;
			parameters[1].Value = model.enterprise_bid;
			parameters[2].Value = model.enterprise_bh;
			parameters[3].Value = model.jobs_name;
			parameters[4].Value = model.jobclass;
			parameters[5].Value = model.workercount;
            if (model.jobdep == "0")
            {
                model.jobdep = "面谈";
            }
			parameters[6].Value = model.jobdep;
			parameters[7].Value = model.salarym;
			parameters[8].Value = model.salaryy;
			parameters[9].Value = model.validity;
			parameters[10].Value = model.workerclass;
			parameters[11].Value = model.edus_id;
			parameters[12].Value = model.workexp_id;
			parameters[13].Value = model.jobduty;
			parameters[14].Value = model.jobrequirement;
			parameters[15].Value = model.releasetime;
			parameters[16].Value = model.isuse;
			parameters[17].Value = model.languages_id;
			parameters[18].Value = model.bcount;
			parameters[19].Value = model.isfrist;
			parameters[20].Value = model.status;
            parameters[21].Value = model.area_name1;
            parameters[22].Value = model.area_name2;
            parameters[23].Value = model.area_name3;
            parameters[24].Value = model.marjor_name1;
            parameters[25].Value = model.marjor_name2;
            parameters[26].Value = model.marjor_name3;
            parameters[27].Value = model.languages_level;
            parameters[28].Value = model.rewardmoney;
            parameters[29].Value = model.job_child_class;


            DbHelperSQL.RunProcedure("P_Add_enterprise_releasejob", parameters, out rowsAffected);
			return (int)parameters[0].Value;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public bool Update(lcmyjobs.Model.enterprise_releasejob model)
		{
			int rowsAffected=0;
			SqlParameter[] parameters = {
					new SqlParameter("@enterprise_rid", SqlDbType.Int,4),
					//new SqlParameter("@enterprise_bid", SqlDbType.Int,4),
					//new SqlParameter("@enterprise_bh", SqlDbType.Char,5),
					new SqlParameter("@jobs_name", SqlDbType.NVarChar,50),
					new SqlParameter("@jobclass", SqlDbType.NVarChar,20),
					new SqlParameter("@workercount", SqlDbType.SmallInt,2),
					new SqlParameter("@jobdep", SqlDbType.NVarChar,20),
					new SqlParameter("@salarym", SqlDbType.VarChar,30),
					new SqlParameter("@salaryy", SqlDbType.VarChar,30),
					new SqlParameter("@validity", SqlDbType.Int,4),
					new SqlParameter("@workerclass", SqlDbType.TinyInt,1),
					new SqlParameter("@edus_id", SqlDbType.Int,4),
					new SqlParameter("@workexp_id", SqlDbType.Int,4),
					new SqlParameter("@jobduty", SqlDbType.NVarChar,1000),
					new SqlParameter("@jobrequirement", SqlDbType.NVarChar,1000),
					new SqlParameter("@releasetime", SqlDbType.DateTime),
					//new SqlParameter("@isuse", SqlDbType.Bit,1),
					new SqlParameter("@languages_id", SqlDbType.Int,4),
                    new SqlParameter("@languages_level", SqlDbType.NVarChar,2),
					//new SqlParameter("@bcount", SqlDbType.Int,4),
					new SqlParameter("@isfrist", SqlDbType.Bit,1),
                    new SqlParameter("@area_name1", SqlDbType.NVarChar,20),   
                    new SqlParameter("@area_name2", SqlDbType.NVarChar,20),
                    new SqlParameter("@area_name3", SqlDbType.NVarChar,20),
                    new SqlParameter("@major_name1", SqlDbType.NVarChar,20),
                    new SqlParameter("@major_name2", SqlDbType.NVarChar,20),
                    new SqlParameter("@major_name3", SqlDbType.NVarChar,20),
                    new SqlParameter("@rewardmoney", SqlDbType.Float),
                    new SqlParameter("@job_child_class",SqlDbType.NVarChar,20)};
			parameters[0].Value = model.enterprise_rid;
			//parameters[1].Value = model.enterprise_bid;
			//parameters[2].Value = model.enterprise_bh;
			parameters[1].Value = model.jobs_name;
			parameters[2].Value = model.jobclass;
			parameters[3].Value = model.workercount;
            if (model.jobdep == "0")
            {
                model.jobdep = "面谈";
            }
			parameters[4].Value = model.jobdep;
			parameters[5].Value = model.salarym;
			parameters[6].Value = model.salaryy;
			parameters[7].Value = model.validity;
			parameters[8].Value = model.workerclass;
			parameters[9].Value = model.edus_id;
			parameters[10].Value = model.workexp_id;
			parameters[11].Value = model.jobduty;
			parameters[12].Value = model.jobrequirement;
			parameters[13].Value = model.releasetime;
			//parameters[16].Value = model.isuse;
			parameters[14].Value = model.languages_id;
            parameters[15].Value = model.languages_level;
			//parameters[18].Value = model.bcount;
			parameters[16].Value = model.isfrist;
            parameters[17].Value = model.area_name1;
            parameters[18].Value = model.area_name2;
            parameters[19].Value = model.area_name3;
            parameters[20].Value = model.marjor_name1;
            parameters[21].Value = model.marjor_name2;
            parameters[22].Value = model.marjor_name3;
            parameters[23].Value = model.rewardmoney;
            parameters[24].Value = model.job_child_class;


            DbHelperSQL.RunProcedure("P_Update_enterprise_releasejob", parameters, out rowsAffected);
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int enterprise_rid)
		{
			int rowsAffected=0;
			SqlParameter[] parameters = {
					new SqlParameter("@enterprise_rid", SqlDbType.Int,4)
};
			parameters[0].Value = enterprise_rid;

            DbHelperSQL.RunProcedure("P_Delete_enterprise_releasejob", parameters, out rowsAffected);
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string enterprise_ridlist )
		{

            int rowsAffected = 0;
            SqlParameter[] parameters = {
					new SqlParameter("@enterprise_rids", SqlDbType.VarChar,300)
};
            parameters[0].Value = enterprise_ridlist;

            DbHelperSQL.RunProcedure("P_Delete_releasejobs", parameters, out rowsAffected);
            if (rowsAffected > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public lcmyjobs.Model.enterprise_releasejob GetModel(int enterprise_rid)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@enterprise_rid", SqlDbType.Int,4)};
			parameters[0].Value = enterprise_rid;

			lcmyjobs.Model.enterprise_releasejob model=new lcmyjobs.Model.enterprise_releasejob();
			DataSet ds= DbHelperSQL.RunProcedure("enterprise_releasejob_GetModel",parameters,"ds");
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["enterprise_rid"].ToString()!="")
				{
					model.enterprise_rid=int.Parse(ds.Tables[0].Rows[0]["enterprise_rid"].ToString());
				}
				if(ds.Tables[0].Rows[0]["enterprise_bid"].ToString()!="")
				{
					model.enterprise_bid=int.Parse(ds.Tables[0].Rows[0]["enterprise_bid"].ToString());
				}
				model.enterprise_bh=ds.Tables[0].Rows[0]["enterprise_bh"].ToString();
				if(ds.Tables[0].Rows[0]["jobs_id"].ToString()!="")
				{
					model.jobs_id=int.Parse(ds.Tables[0].Rows[0]["jobs_id"].ToString());
				}
				model.jobclass=ds.Tables[0].Rows[0]["jobclass"].ToString();
				if(ds.Tables[0].Rows[0]["workercount"].ToString()!="")
				{
					model.workercount=int.Parse(ds.Tables[0].Rows[0]["workercount"].ToString());
				}
				model.jobdep=ds.Tables[0].Rows[0]["jobdep"].ToString();
				model.salarym=ds.Tables[0].Rows[0]["salarym"].ToString();
				model.salaryy=ds.Tables[0].Rows[0]["salaryy"].ToString();
				if(ds.Tables[0].Rows[0]["validity"].ToString()!="")
				{
					model.validity=int.Parse(ds.Tables[0].Rows[0]["validity"].ToString());
				}
				if(ds.Tables[0].Rows[0]["workerclass"].ToString()!="")
				{
					model.workerclass=int.Parse(ds.Tables[0].Rows[0]["workerclass"].ToString());
				}
				if(ds.Tables[0].Rows[0]["edus_id"].ToString()!="")
				{
					model.edus_id=int.Parse(ds.Tables[0].Rows[0]["edus_id"].ToString());
				}
				if(ds.Tables[0].Rows[0]["workexp_id"].ToString()!="")
				{
					model.workexp_id=int.Parse(ds.Tables[0].Rows[0]["workexp_id"].ToString());
				}
				model.jobduty=ds.Tables[0].Rows[0]["jobduty"].ToString();
				model.jobrequirement=ds.Tables[0].Rows[0]["jobrequirement"].ToString();
				if(ds.Tables[0].Rows[0]["releasetime"].ToString()!="")
				{
					model.releasetime=DateTime.Parse(ds.Tables[0].Rows[0]["releasetime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["isuse"].ToString()!="")
				{
					if((ds.Tables[0].Rows[0]["isuse"].ToString()=="1")||(ds.Tables[0].Rows[0]["isuse"].ToString().ToLower()=="true"))
					{
						model.isuse=true;
					}
					else
					{
						model.isuse=false;
					}
				}
				if(ds.Tables[0].Rows[0]["languages_id"].ToString()!="")
				{
					model.languages_id=int.Parse(ds.Tables[0].Rows[0]["languages_id"].ToString());
				}
				model.languages_level=ds.Tables[0].Rows[0]["languages_level"].ToString();
				if(ds.Tables[0].Rows[0]["bcount"].ToString()!="")
				{
					model.bcount=int.Parse(ds.Tables[0].Rows[0]["bcount"].ToString());
				}
				if(ds.Tables[0].Rows[0]["isfrist"].ToString()!="")
				{
					if((ds.Tables[0].Rows[0]["isfrist"].ToString()=="1")||(ds.Tables[0].Rows[0]["isfrist"].ToString().ToLower()=="true"))
					{
						model.isfrist=true;
					}
					else
					{
						model.isfrist=false;
					}
				}
				if(ds.Tables[0].Rows[0]["status"].ToString()!="")
				{
					model.status=int.Parse(ds.Tables[0].Rows[0]["status"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}
		

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select enterprise_rid,enterprise_bid,enterprise_bh,jobs_id,jobclass,workercount,jobdep,salarym,salaryy,validity,workerclass,edus_id,workexp_id,jobduty,jobrequirement,releasetime,isuse,languages_id,bcount,isfrist,status ");
			strSql.Append(" FROM enterprise_releasejob ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" enterprise_rid,enterprise_bid,enterprise_bh,jobs_id,jobclass,workercount,jobdep,salarym,salaryy,validity,workerclass,edus_id,workexp_id,jobduty,jobrequirement,releasetime,isuse,languages_id,bcount,isfrist,status ");
			strSql.Append(" FROM enterprise_releasejob ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "enterprise_releasejob";
			parameters[1].Value = "enterprise_rid";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

